function info(message) { if (console) { console.log("INFO: " + message); } } function debug(message) { if (console) { console.log("DEBUG: " + message); } } function error(message) { if (console) { console.error("DEBUG: " + message); } window.alert("ERROR: " + message); } /* Code duplicated: see CodeforcesIframeInit.js */ function appendParameterToUrl(url, parameterName, parameterValue) { if (!parameterName || parameterName.length === 0) { return url; } var parameter = !parameterValue || parameterValue.length === 0 ? encodeURIComponent(parameterName) : encodeURIComponent(parameterName) + "=" + encodeURIComponent(parameterValue); var questionSignPos = url.indexOf("?"); var sharpPos = url.indexOf("#"); if (questionSignPos === -1 && sharpPos === -1) { return url + "?" + parameter; } else if (questionSignPos === -1 || questionSignPos > sharpPos && sharpPos !== -1) { return url.substring(0, sharpPos) + "?" + parameter + url.substring(sharpPos); } else { var resultUrl = url.substring(0, questionSignPos + 1) + parameter; return url.length > questionSignPos + 1 ? resultUrl + "&" + url.substring(questionSignPos + 1) : resultUrl; } } $.fn.hasAttr = function (name) { var attr = $(this).attr(name); return typeof attr !== 'undefined' && attr !== false; }; $.fn.submitOnce = function (callback, alwaysDisable) { $(this).each(function () { var button = $(this).find("input[type=submit]"); var img = $(this).find(".ajax-loading-gif"); $(this).submit(function () { if ($(this).hasAttr("data-submitting")) { return true; } if (button.prop("disabled")) { return false; } var result = callback.call(this); if (result || alwaysDisable) { img.show(); button.prop("disabled", true); setTimeout(function () { img.hide(); button.prop("disabled", false); }, alwaysDisable ? 1000 : 10000); } return result; }); }); }; $.fn.doSubmit = function () { $(this).attr("data-submitting", "true"); $(this).submit(); $(this).removeAttr("data-submitting"); }; Codeforces = new function () { //noinspection JSUnusedGlobalSymbols this.queryString = function () { // This function is anonymous, is executed immediately and // the return value is assigned to QueryString! var query_string = {}; var query = window.location.search.substring(1); var vars = query.split("&"); for (var i = 0; i < vars.length; i++) { var pair = vars[i].split("="); // If first entry with this name if (typeof query_string[pair[0]] === "undefined") { query_string[pair[0]] = decodeURIComponent(pair[1]); // If second entry with this name } else if (typeof query_string[pair[0]] === "string") { query_string[pair[0]] = [query_string[pair[0]], decodeURIComponent(pair[1])]; // If third or later entry with this name } else { query_string[pair[0]].push(decodeURIComponent(pair[1])); } } return query_string; }(); this.updateUrlParameter = function (url, param, paramVal) { var TheAnchor = null; var newAdditionalURL = ""; var tempArray = url.split("?"); var baseURL = tempArray[0]; var additionalURL = tempArray[1]; var temp = ""; var tmpAnchor; var TheParams; if (additionalURL) { tmpAnchor = additionalURL.split("#"); TheParams = tmpAnchor[0]; TheAnchor = tmpAnchor[1]; if (TheAnchor) additionalURL = TheParams; tempArray = additionalURL.split("&"); for (var i = 0; i < tempArray.length; i++) { if (tempArray[i].split('=')[0] != param) { newAdditionalURL += temp + tempArray[i]; temp = "&"; } } } else { tmpAnchor = baseURL.split("#"); TheParams = tmpAnchor[0]; TheAnchor = tmpAnchor[1]; if (TheParams) baseURL = TheParams; } if (TheAnchor) paramVal += "#" + TheAnchor; var rows_txt = temp + "" + param + "=" + paramVal; return baseURL + "?" + newAdditionalURL + rows_txt; }; this.showAnnouncements = function (json, locale) { var div = document.getElementsByClassName("notificationTextCleaner")[0]; var messages = []; for (var i = 0; i < json.length; ++i) { if (Codeforces.getFromStorage("Announcement-" + json[i].id, false)) { console.log("Skipped announcement " + json[i].id); continue; } Codeforces.putToStorage("Announcement-" + json[i].id, true); //noinspection InnerHTMLJS var announcementText = json[i].text; if (!announcementText) { if (locale == "ru") { announcementText = json[i].russianText; } else { announcementText = json[i].englishText; } if (!announcementText) { announcementText = json[i].russianText; } if (!announcementText) { announcementText = json[i].englishText; } } div.innerHTML = announcementText; var name = json[i].name; if (!name) { if (locale == "ru") { name = json[i].russianName; } else { name = json[i].englishName; } } var text = div.innerText || div.textContent || div.text; if (window.Notification) { if (Notification.permission === "default") { Notification.requestPermission(); } if (Notification.permission === "granted") { //noinspection ObjectAllocationIgnored new Notification(name, { body: text, icon: "../favicon.png" }); } } messages.push({name: name, text: text}); } setTimeout(function () { for (var messageIndex = 0; messageIndex < messages.length; ++messageIndex) { var message = messages[messageIndex]; alert(message.name + "\n----------\n\n" + message.text); } }, 1); }; this.ping = function (pingUrl) { var millis = new Date().getTime(); Codeforces.putToStorage("LastOnlineTimeUpdaterMillis", millis); Codeforces.setCookie("lastOnlineTimeUpdaterInvocation", millis); //info("ping: " + (millis / 1000)); $.post(pingUrl, { ftaa: window._ftaa, bfaa: window._bfaa, clientUtcOffsetMinutes: Codeforces.getLocalUtcOffset(), clientUtcOffsetString: Codeforces.formatTimezone(moment(), false, true) }, function (result) { Codeforces.showAnnouncements(result); }, "json"); }; this.parseSeconds = function (seconds) { var ap = 0; if (seconds.length == 9) { ap = seconds.charAt(0) - '0'; seconds = seconds.substring(1); } if (seconds.length == 8 && seconds.charAt(2) == ':' && seconds.charAt(5) == ':') { var s = (seconds.charAt(7) - '0') + 10 * (seconds.charAt(6) - '0'); var m = (seconds.charAt(4) - '0') + 10 * (seconds.charAt(3) - '0'); var h = (seconds.charAt(1) - '0') + 10 * (seconds.charAt(0) - '0') + 100 * ap; return s + 60 * m + 60 * 60 * h; } else { return 0; } }; this.formatSS = function (seconds) { if (seconds <= 9) { return "0" + seconds; } else { return seconds; } }; this.formatSeconds = function (seconds) { var s = seconds % 60; seconds = (seconds - s) / 60; var m = seconds % 60; var h = (seconds - m) / 60; return Codeforces.formatSS(h) + ":" + Codeforces.formatSS(m) + ":" + Codeforces.formatSS(s); }; this.getUtcOffset = function () { if (Codeforces.utc_offset == undefined) { Codeforces.utc_offset = $("meta[name=\"utc_offset\"]").attr("content"); } return Codeforces.utc_offset; }; this.getLocalUtcOffset = function () { if (Codeforces.local_utc_offset == undefined) { Codeforces.local_utc_offset = moment().local().utcOffset(); } return Codeforces.local_utc_offset; }; this.addTimeZoneNotice = function ($lastDatetimePickerInput) { var offsetString = ""; var m = moment().utcOffset(Codeforces.getLocalUtcOffset()); if (m.utcOffset() != 0) { offsetString += " " + moment().format("Z"); } var notice = "(" + window.codeforcesOptions.timeZoneNoticeCaption + offsetString + ")"; $lastDatetimePickerInput.after($("").text(notice)); }; var ruTime = "DD.MM.YYYY HH:mm"; var enTime = "MMM/DD/YYYY HH:mm"; var ruTimeWithDow = "dddd, LL [в] HH:mm";//"dddd, DD.MMMM.YYYY HH:mm"; var enTimeWithDow = "dddd, LL [at] HH:mm";//"dddd, MMM/DD/YYYY HH:mm"; var ruTimeOnly = "HH:mm"; var enTimeOnly = "HH:mm"; var systemTimeWithSeconds = "YYYY-MM-DD HH:mm:ss"; var ruTimeWithSeconds = "DD.MM.YYYY HH:mm:ss"; var enTimeWithSeconds = "MMM/DD/YYYY HH:mm:ss"; var ruDate = "DD.MM.YYYY"; var enDate = "MMM/DD/YYYY"; this.reformatTime = function (timeString) { var dateString = timeString + " " + Codeforces.getUtcOffset(); var m = moment(dateString, ruTime + " Z"); var timeFormat = ruTime; if (!m.isValid()) { m = moment(dateString, enTime + " Z"); timeFormat = enTime; } m = m.utcOffset(Codeforces.getLocalUtcOffset()); return m.format(timeFormat); }; this.formatTimezone = function (m, wrapInHtml, returnCodeforcesOffset) { if (!returnCodeforcesOffset && m.format("Z") == Codeforces.getUtcOffset()) { return ""; } var off = m.utcOffset(); var offset = "UTC"; if (off != 0) { if (off > 0) offset += "+"; else offset += "-"; off = Math.round(Math.abs(off)); offset += Math.floor(off / 60); if (off % 60 != 0) { if (off % 60 == 30) { offset += ".5"; } else { offset += ":"; if (off % 60 < 10) offset += "0"; offset += off % 60; } } } if (wrapInHtml) { return "" + offset + ""; } else { return " " + offset; } }; this.reformatTimes = function () { $(".format-time-with-dow").each(function () { var dateString = $(this).text(); if (dateString.indexOf("(") != -1) { dateString = dateString.substr(0, dateString.indexOf("(")); } dateString = dateString + " " + Codeforces.getUtcOffset(); var m = moment(dateString, ruTime + " Z"); var timeFormat = ruTimeWithDow; if (!m.isValid()) { m = moment(dateString, enTime + " Z"); timeFormat = enTimeWithDow; } else { m.locale("ru"); } m = m.utcOffset(Codeforces.getLocalUtcOffset()); $(this).replaceWith(m.format(timeFormat) + Codeforces.formatTimezone(m, true)); }); $(".format-time").each(function () { var dateString = $(this).text() + " " + Codeforces.getUtcOffset(); var m = moment(dateString, ruTime + " Z"); var timeFormat = ruTime; if (!m.isValid()) { m = moment(dateString, enTime + " Z"); timeFormat = enTime; } m = m.utcOffset(Codeforces.getLocalUtcOffset()); $(this).replaceWith(m.format(timeFormat) + Codeforces.formatTimezone(m, true)); }); $(".format-time-only").each(function () { var dateString = $(this).text() + " " + Codeforces.getUtcOffset(); var m = moment(dateString, ruTime + " Z"); var timeFormat = ruTimeOnly; if (!m.isValid()) { m = moment(dateString, enTime + " Z"); timeFormat = enTimeOnly; } m = m.utcOffset(Codeforces.getLocalUtcOffset()); $(this).replaceWith(m.format(timeFormat) + Codeforces.formatTimezone(m, true)); }); $(".format-systemtimewithseconds").each(function () { var dateString = $(this).text() + " " + Codeforces.getUtcOffset(); var m = moment(dateString, systemTimeWithSeconds + " Z"); m = m.utcOffset(Codeforces.getLocalUtcOffset()); $(this).replaceWith(m.format(systemTimeWithSeconds) + Codeforces.formatTimezone(m, true)); }); $(".format-timewithseconds").each(function () { var dateString = $(this).text() + " " + Codeforces.getUtcOffset(); var m = moment(dateString, ruTimeWithSeconds + " Z"); var timeFormat = ruTimeWithSeconds; if (!m.isValid()) { m = moment(dateString, enTimeWithSeconds + " Z"); timeFormat = enTimeWithSeconds; } m = m.utcOffset(Codeforces.getLocalUtcOffset()); $(this).replaceWith(m.format(timeFormat) + Codeforces.formatTimezone(m, true)); }); $(".format-humantime").each(function () { var dateString = $(this).attr("title") + " " + Codeforces.getUtcOffset(); var m = moment(dateString, ruTime + " Z"); var timeFormat = ruTime; if (!m.isValid()) { m = moment(dateString, enTime + " Z"); timeFormat = enTime; } m = m.utcOffset(Codeforces.getLocalUtcOffset()); $(this).attr("title", m.format(timeFormat) + Codeforces.formatTimezone(m, false)); }); $(".format-date").each(function () { var dateString = $(this).text() + " " + Codeforces.getUtcOffset(); var m = moment(dateString, ruTime + " Z"); var dateFormat = ruDate; if (!m.isValid()) { m = moment(dateString, enTime + " Z"); dateFormat = enDate; } m = m.utcOffset(Codeforces.getLocalUtcOffset()); $(this).replaceWith(m.format(dateFormat)); }); }; this.setupFormDatetimePicker = function ($initialDatetimeInput, $dayInput, $timeInput, $clientTimezoneOffsetInput) { $clientTimezoneOffsetInput.val(moment().utcOffset(Codeforces.getLocalUtcOffset()).utcOffset()); var timeText = $initialDatetimeInput.val(); if (!timeText || $dayInput.val() || $timeInput.val()) { return; } timeText = Codeforces.reformatTime(timeText); var tokens = timeText.split(' '); $dayInput.val(tokens[0]); $timeInput.val(tokens[1]); }; this.countdown = function () { var now = new Date().getTime(); var countdownElements = $(".countdown"); var starts = []; var index = 0; countdownElements.each(function () { ++index; $(this).attr("cdid", "i" + index); }); var callback = function () { countdownElements.each(function () { var countdownElement = $(this); var textBeforeRedirect = countdownElement.attr("textBeforeRedirect"); var redirectUrl = countdownElement.attr("redirectUrl"); var home = countdownElement.attr("home"); var noRedirection = countdownElement.attr("noRedirection"); var hideOnCountdownFinish = countdownElement.attr("hideOnCountdownFinish"); var showAnotherOnCountdownFinish = countdownElement.attr("showAnotherOnCountdownFinish"); var showAnotherClass = countdownElement.attr("showAnotherClass"); var hideAnotherOnCountdownFinish = countdownElement.attr("hideAnotherOnCountdownFinish"); var hideAnotherClass = countdownElement.attr("hideAnotherClass"); var id = countdownElement.attr("cdid"); var txt = countdownElement.text(); var s = Codeforces.parseSeconds(txt); if (s > 0) { if (starts[id] == undefined) { starts[id] = s; } var passed = Math.floor((new Date().getTime() - now) / 1000); var val = Math.max(0, starts[id] - passed); countdownElement.text(Codeforces.formatSeconds(val)); if (val <= 0) { if (hideOnCountdownFinish == "true" || hideOnCountdownFinish == "yes" || hideOnCountdownFinish == "y" || hideOnCountdownFinish == "1") { countdownElement.hide(); } if (showAnotherOnCountdownFinish == "true" || showAnotherOnCountdownFinish == "yes" || showAnotherOnCountdownFinish == "y" || showAnotherOnCountdownFinish == "1") { $("." + showAnotherClass).show(); } if (hideAnotherOnCountdownFinish == "true" || hideAnotherOnCountdownFinish == "yes" || hideAnotherOnCountdownFinish == "y" || hideAnotherOnCountdownFinish == "1") { $("." + hideAnotherClass).hide(); } if (noRedirection != "true" && noRedirection != "yes" && noRedirection != "y" && noRedirection != "1") { if (textBeforeRedirect) { Codeforces.alert(textBeforeRedirect, function () { if (redirectUrl) { window.setTimeout(Codeforces.redirect(redirectUrl), Math.floor(Math.random() * 2000)); } else { window.setTimeout(Codeforces.reload, Math.floor(Math.random() * 2000)); } }); } else { if (redirectUrl) { window.setTimeout(Codeforces.redirect(redirectUrl), Math.floor(Math.random() * 5000)); } else { window.setTimeout(Codeforces.reload, Math.floor(Math.random() * 5000)); } } } else { if (textBeforeRedirect) { Codeforces.alert(textBeforeRedirect); } } } } }); window.setTimeout(callback, 1000); }; window.setTimeout(callback, 0); }; this.facebox = function (target, home) { $("facebox").facebox(/*{ closeImage : (home != undefined ? home + "/" : "") + 'images/facebox/closelabel.gif', splitterImage : (home != undefined ? home + "/" : "") + 'images/facebox/splitter.png' }*/); $.facebox.loading(); var clone = $(target).clone(); $.facebox.reveal(clone.show(), null); CodeforcesIframe.updatePopups(); }; this.template = function (selector) { let $result = $(selector).clone(); $result.css("display", "block"); return $result; } this.alert = function (messageHtml, okHandler, okText) { Codeforces.confirm(messageHtml, okHandler, null, okText, null); }; this.confirm = function (messageHtml, okHandler, cancelHandler, okText, cancelText, noClose) { if (typeof(noClose) === 'undefined') { noClose = false; } var dialogHtml = "